//
//  JokeTableViewCell.m
//  UI_Project_A
//
//  Created by dllo on 16/1/30.
//  Copyright © 2016年 GH. All rights reserved.
//

#import "JokeTableViewCell.h"
#import <UIImageView+WebCache.h>
#import "ModelOfJoke.h"
#import <DKNightVersion.h>

@interface JokeTableViewCell ()

@property (nonatomic ,retain)UIView *viewOftemp;
@property (nonatomic ,retain)UIImageView *imageViewOfpic;
@property (nonatomic ,retain)UIImageView *imageViewOfHead;
@property (nonatomic ,retain)UILabel *label;
@property (nonatomic ,retain)UILabel *labelContect;
@property (nonatomic ,retain)UILabel *labelOfculture;
@property (nonatomic ,retain)UILabel *labelOfFollow;
@property (nonatomic ,retain)UILabel *labelOfQuestion;
@property (nonatomic ,retain)UILabel *labelOftitle;
@property (nonatomic ,retain)UIButton *buttionOffollow;

@end

@implementation JokeTableViewCell

- (void)dealloc {

    [_viewOftemp release];
    [_imageViewOfpic release];
    [_imageViewOfHead release];
    [_label release];
    [_labelContect release];
    [_labelOfculture release];
    [_labelOfFollow release];
    [_labelOfQuestion release];
    [_labelOftitle release];
    [_buttionOffollow release];
    [super dealloc];

}



- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {

    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    
    if (self) {
        [self createView];
        [self createImageview];
        [self createLabel];
        [self createButton];
    }


    return self;
}



- (void)createButton {

    self.buttionOffollow = [UIButton buttonWithType:UIButtonTypeCustom];
    [self.contentView addSubview:self.buttionOffollow];
    self.buttionOffollow.backgroundColor = [UIColor redColor];

    [self.buttionOffollow setTitle:@"+ 关注" forState:UIControlStateNormal];
    [self.buttionOffollow setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
//    self.buttionOffollow.layer.masksToBounds = YES;
    self.buttionOffollow.layer.cornerRadius = 20;

    [self.buttionOffollow addTarget:self action:@selector(click:) forControlEvents:UIControlEventTouchUpInside];

}


- (void)click:(UIButton *)button {
    

    button.backgroundColor = [UIColor whiteColor];
    [button setTitle:@"√ 已关注" forState:UIControlStateNormal];
    [button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
//    button.layer.masksToBounds = YES;
//    button.layer.cornerRadius= 20;


}



-(void)createView {

    self.viewOftemp = [[UIView alloc] init];
    [self.contentView addSubview:self.viewOftemp];
    [self.viewOftemp release];
    self.viewOftemp.layer.masksToBounds = YES;
    self.viewOftemp.layer.cornerRadius = 5;
    self.viewOftemp.layer.borderWidth = 1;
    self.viewOftemp.layer.borderColor = [UIColor lightGrayColor].CGColor;
    self.viewOftemp.layer.shadowOffset = CGSizeMake(0, 1);
   self.viewOftemp.layer.shadowOpacity = 0.2;





}

-(void)passModelWith:(ModelOfJoke *)model {

    [self.imageViewOfHead sd_setImageWithURL:[NSURL URLWithString:model.headpicurl]];
    [self.imageViewOfpic sd_setImageWithURL:[NSURL URLWithString:model.picurl]];

    
    //关注
    self.labelContect.text = model.alias;
    self.label.text = model.name;
    self.labelOfculture.text = model.classification;
    self.labelOfculture.textColor = [UIColor redColor];
   
    NSInteger follow =  model.concernCount.integerValue;
    if (follow > 10000) {

    NSInteger w = follow /10000;
        NSInteger q = follow /1000;
        q = q % 10;
        
        NSString *concer = [NSString stringWithFormat:@"%ld.%ld万关注",w,q];
        self.labelOfFollow.text = concer;
    }else {
        NSString *concer = [NSString stringWithFormat:@"%ld关注",follow];
        self.labelOfFollow.text = concer;
    
    }
    self.labelOfFollow.textColor = [UIColor grayColor];
    
    //提问
    
    NSString *question = [NSString stringWithFormat:@"%@提问",model.questionCount];
    self.labelOfQuestion.text = question;
    self.labelOfQuestion.textColor = [UIColor grayColor];
    
    //title
    NSString * title = [NSString stringWithFormat:@"/ %@",model.title];
    self.labelOftitle.text = title;
}


- (void)createLabel {
    self.label = [[UILabel alloc] init];
    [self.contentView addSubview:self.label];
    self.label.font = [UIFont systemFontOfSize:15];
    self.label.dk_textColorPicker = DKColorWithColors([UIColor colorWithWhite:0.247 alpha:1.000],[UIColor whiteColor]);
    
    
    self.labelContect = [[UILabel alloc] init];
    [self.contentView addSubview:self.labelContect];
    self.labelContect.numberOfLines = 0;
    self.labelContect.font = [UIFont systemFontOfSize:21];
    self.labelContect.dk_textColorPicker = DKColorWithColors([UIColor colorWithWhite:0.247 alpha:1.000],[UIColor whiteColor]);

    
    
    self.labelOfculture = [[UILabel alloc] init];
    [self.contentView addSubview:self.labelOfculture];
    self.labelOfculture.font = [UIFont systemFontOfSize:15];
    self.labelOfculture.dk_textColorPicker = DKColorWithColors([UIColor colorWithWhite:0.247 alpha:1.000],[UIColor whiteColor]);
    
    
    //关注
    self.labelOfFollow = [[UILabel alloc]init];
    [self.contentView addSubview:self.labelOfFollow];
    self.labelOfFollow.font = [UIFont systemFontOfSize:16];
    self.labelOfFollow.dk_textColorPicker = DKColorWithColors([UIColor colorWithWhite:0.247 alpha:1.000],[UIColor whiteColor]);
    
    
    //提问
    self.labelOfQuestion = [[UILabel alloc] init];
    [self.contentView addSubview:self.labelOfQuestion];
    self.labelOfQuestion.font = [UIFont systemFontOfSize:16];
    self.labelOfQuestion.dk_textColorPicker = DKColorWithColors([UIColor colorWithWhite:0.247 alpha:1.000],[UIColor whiteColor]);
    
    //title
    self.labelOftitle = [[UILabel alloc] init];
    [self.contentView addSubview:self.labelOftitle];
    self.labelOftitle.font = [UIFont systemFontOfSize:15];
    self.labelOftitle.dk_textColorPicker = DKColorWithColors([UIColor colorWithWhite:0.247 alpha:1.000],[UIColor whiteColor]);
    
    
    
    
    
    
}
- (void)createImageview {
    self.imageViewOfHead = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@""]];
[self.contentView addSubview:self.imageViewOfHead];
    [self.imageViewOfHead release];
    self.imageViewOfHead.backgroundColor = [UIColor redColor];
    self.imageViewOfHead.layer.masksToBounds = YES;
    self.imageViewOfHead.layer.cornerRadius = 20;
    
    
    

    self.imageViewOfpic = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@""]];
    [self.contentView addSubview:self.imageViewOfpic];
    [self.imageViewOfpic release];
    self.imageViewOfpic.backgroundColor = [UIColor whiteColor];
    

}

- (void)layoutSubviews {

    [super layoutSubviews];
    
    self.viewOftemp.frame = CGRectMake(10, 10, self.frame.size.width - 20, self.frame.size.height - 20);
    self.imageViewOfHead.frame = CGRectMake(20, 20, 40, 40);
    self.imageViewOfpic.frame = CGRectMake(14, 65, self.frame.size.width-28, self.frame.size.height/2);
    self.label.frame = CGRectMake(70, 15, 60, 40);
    self.labelContect.frame = CGRectMake(20, self.frame.size.height/2 + 60, self.frame.size.width - 20, 80);
    self.labelOfculture.frame = CGRectMake(20, self.frame.size.height - 60, 30, 30);
    self.labelOfFollow.frame = CGRectMake(55, self.frame.size.height - 60, 80, 30);
    self.labelOfQuestion.frame = CGRectMake(135, self.frame.size.height - 60, 80, 30);
    self.labelOftitle.frame = CGRectMake(120, 15, self.frame.size.width - 160, 40);
    
    self.buttionOffollow.frame = CGRectMake(self.frame.size.width - 120, self.frame.size.height - 65, 80, 40);
}

- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
